package com.example.tms.mapper;

import com.example.tms.bean.OilcardMgmt;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

/**
 * 油卡管理
 */
public interface OilcardMapper extends JpaRepository<OilcardMgmt,String>, JpaSpecificationExecutor<OilcardMgmt> {

    //查询油卡信息（油卡id）
    @Query(value = "select * from oilcard_mgmt where ykid = ?1 and sfcz = true ", nativeQuery = true)
    OilcardMgmt findByYkid(String ykid);

    //删除油卡信息（假删除 油卡id）
    @Query(value = "update oilcard_mgmt set sfcz = false where ykid = ?1", nativeQuery = true)
    @Modifying
    @Transactional
    void DeleteByYkid(String ykid);

    //查询油卡信息（油卡号）
    @Query(value = "select * from oilcard_mgmt where ykh = ?1 and sfcz = true ", nativeQuery = true)
    OilcardMgmt findByYkh(String ykh);
}
